/**
 * 
 */
package com.dp.behav.visitor;

/**
 * @author Sunaina.Sharma
 * 
 *         The ConcreteVisitor implements the operations defined in the Visitor
 *         interface. The concrete visitor will store local state, typically as
 *         it traverses the set of elements. The element interface simply
 *         defines an accept method to allow the visitor to run some action over
 *         that element
 * 
 */
public class PostageVisitor implements Visitor {
	private double totalPostageForCart;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.dp.behav.visitor.Visitor#visit(com.dp.behav.visitor.Book)
	 * collect data about the book
	 */
	public void visit(Book book) {
		// assume we have a calculation here related to weight and price
		// free postage for a book over 10
		if (book.getPrice() < 10.0) {
			totalPostageForCart += book.getWeight() * 2;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.dp.behav.visitor.Visitor#visit(com.dp.behav.visitor.CD)
	 */
	public void visit(CD cd) {
		// We can write implementation here

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.dp.behav.visitor.Visitor#visit(com.dp.behav.visitor.DVD)
	 */
	public void visit(DVD dvd) {
		// We can write implementation here
	}

	/**
	 * @return the internal state
	 */
	public double getTotalPostage() {
		return totalPostageForCart;
	}
}
